/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sadfinanceiro;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 *
 * @author daniel
 */
public class SADFinanceiroGraficoView extends javax.swing.JFrame {

    /**
     * Creates a new demo.
     *
     * @param title  the frame title.
     */
    public SADFinanceiroGraficoView(CategoryDataset dataset) {

        super("");

        JFreeChart chart = createChart(dataset);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartPanel);

    }

   
    /**
     * Creates a sample chart.
     * 
     * @param dataset  a dataset.
     * 
     * @return The chart.
     */
    private JFreeChart createChart(CategoryDataset dataset) {
        
        // create the chart...
        JFreeChart chart = ChartFactory.createLineChart(
            "Gráfico dos cenários",       // chart title
            "",                    // domain axis label
            "",                   // range axis label
            dataset,                   // data
            PlotOrientation.VERTICAL,  // orientation
            true,                      // include legend
            true,                      // tooltips
            false                      // urls
        );

        chart.setBackgroundPaint(Color.white);

        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setRangeGridlinePaint(Color.white);

        // customise the range axis...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeIncludesZero(true);
        rangeAxis.setUpperMargin(0.20);
        rangeAxis.setLabelAngle(Math.PI / 2.0);
     
        // customise the renderer...
        LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
        //srenderer.setDrawShapes(true);

        renderer.setSeriesStroke(
            0, new BasicStroke(3.0f,
                               BasicStroke.CAP_ROUND,
                               BasicStroke.JOIN_ROUND,
                               1.0f,
                               new float[] {10.0f, 6.0f},
                               0.0f)
        );
        
        renderer.setSeriesStroke(
            1, new BasicStroke(3.0f,
                               BasicStroke.CAP_ROUND,
                               BasicStroke.JOIN_ROUND,
                               1.0f,
                               new float[] {10.0f, 6.0f},
                               0.0f)
        );
 
        renderer.setSeriesStroke(
            2, new BasicStroke(3.0f,
                               BasicStroke.CAP_ROUND,
                               BasicStroke.JOIN_ROUND,
                               1.0f,
                               new float[] {10.0f, 6.0f},
                               0.0f)
        );
  
        renderer.setSeriesStroke(
            3, new BasicStroke(3.0f,
                               BasicStroke.CAP_ROUND,
                               BasicStroke.JOIN_ROUND,
                               1.0f,
                               new float[] {10.0f, 6.0f},
                               0.0f)
        );
   
        renderer.setSeriesStroke(
            4, new BasicStroke(3.0f,
                               BasicStroke.CAP_ROUND,
                               BasicStroke.JOIN_ROUND,
                               1.0f,
                               new float[] {10.0f, 6.0f},
                               0.0f)
        );
    
        
        renderer.setItemLabelsVisible(true);
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition());
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition());
        // OPTIONAL CUSTOMISATION COMPLETED.
        
        return chart;
    }

}
